<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>filedownloader_test.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="local_closure_goog_net_filedownloader_test.js.html">filedownloader_test.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2011 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>goog.provide(&#39;goog.net.FileDownloaderTest&#39;);
<a name="line16"></a>goog.setTestOnly(&#39;goog.net.FileDownloaderTest&#39;);
<a name="line17"></a>
<a name="line18"></a>goog.require(&#39;goog.fs.Error&#39;);
<a name="line19"></a>goog.require(&#39;goog.net.ErrorCode&#39;);
<a name="line20"></a>goog.require(&#39;goog.net.FileDownloader&#39;);
<a name="line21"></a>goog.require(&#39;goog.net.XhrIo&#39;);
<a name="line22"></a>goog.require(&#39;goog.testing.AsyncTestCase&#39;);
<a name="line23"></a>goog.require(&#39;goog.testing.PropertyReplacer&#39;);
<a name="line24"></a>goog.require(&#39;goog.testing.fs&#39;);
<a name="line25"></a>goog.require(&#39;goog.testing.fs.FileSystem&#39;);
<a name="line26"></a>goog.require(&#39;goog.testing.jsunit&#39;);
<a name="line27"></a>goog.require(&#39;goog.testing.net.XhrIoPool&#39;);
<a name="line28"></a>
<a name="line29"></a>var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall();
<a name="line30"></a>var xhrIoPool, xhr, fs, dir, downloader;
<a name="line31"></a>
<a name="line32"></a>function setUpPage() {
<a name="line33"></a>  goog.testing.fs.install(new goog.testing.PropertyReplacer());
<a name="line34"></a>}
<a name="line35"></a>
<a name="line36"></a>function setUp() {
<a name="line37"></a>  xhrIoPool = new goog.testing.net.XhrIoPool();
<a name="line38"></a>  xhr = xhrIoPool.getXhr();
<a name="line39"></a>  fs = new goog.testing.fs.FileSystem();
<a name="line40"></a>  dir = fs.getRoot();
<a name="line41"></a>  downloader = new goog.net.FileDownloader(dir, xhrIoPool);
<a name="line42"></a>}
<a name="line43"></a>
<a name="line44"></a>function tearDown() {
<a name="line45"></a>  goog.dispose(downloader);
<a name="line46"></a>}
<a name="line47"></a>
<a name="line48"></a>function testDownload() {
<a name="line49"></a>  downloader.download(&#39;/foo/bar&#39;).addCallback(function(blob) {
<a name="line50"></a>    var fileEntry = dir.getFileSync(&#39;`3fa/``2Ffoo`2Fbar/`bar&#39;);
<a name="line51"></a>    assertEquals(&#39;data&#39;, blob.toString());
<a name="line52"></a>    assertEquals(&#39;data&#39;, fileEntry.fileSync().toString());
<a name="line53"></a>    asyncTestCase.continueTesting();
<a name="line54"></a>  }).addErrback(function(err) { throw err; });
<a name="line55"></a>
<a name="line56"></a>  assertEquals(&#39;/foo/bar&#39;, xhr.getLastUri());
<a name="line57"></a>  assertEquals(goog.net.XhrIo.ResponseType.ARRAY_BUFFER, xhr.getResponseType());
<a name="line58"></a>
<a name="line59"></a>  xhr.simulateResponse(200, &#39;data&#39;);
<a name="line60"></a>  asyncTestCase.waitForAsync(&#39;testDownload&#39;);
<a name="line61"></a>}
<a name="line62"></a>
<a name="line63"></a>function testGetDownloadedBlob() {
<a name="line64"></a>  downloader.download(&#39;/foo/bar&#39;).
<a name="line65"></a>      addCallback(function() {
<a name="line66"></a>        return downloader.getDownloadedBlob(&#39;/foo/bar&#39;);
<a name="line67"></a>      }).
<a name="line68"></a>      addCallback(function(blob) { assertEquals(&#39;data&#39;, blob.toString()); }).
<a name="line69"></a>      addCallback(goog.bind(asyncTestCase.continueTesting, asyncTestCase)).
<a name="line70"></a>      addErrback(function(err) { throw err; });
<a name="line71"></a>
<a name="line72"></a>  xhr.simulateResponse(200, &#39;data&#39;);
<a name="line73"></a>  asyncTestCase.waitForAsync(&#39;testGetDownloadedBlob&#39;);
<a name="line74"></a>}
<a name="line75"></a>
<a name="line76"></a>function testGetLocalUrl() {
<a name="line77"></a>  downloader.download(&#39;/foo/bar&#39;).
<a name="line78"></a>      addCallback(function() { return downloader.getLocalUrl(&#39;/foo/bar&#39;); }).
<a name="line79"></a>      addCallback(function(url) { assertMatches(/\/`bar$/, url); }).
<a name="line80"></a>      addCallback(goog.bind(asyncTestCase.continueTesting, asyncTestCase)).
<a name="line81"></a>      addErrback(function(err) { throw err; });
<a name="line82"></a>
<a name="line83"></a>  xhr.simulateResponse(200, &#39;data&#39;);
<a name="line84"></a>  asyncTestCase.waitForAsync(&#39;testGetLocalUrl&#39;);
<a name="line85"></a>}
<a name="line86"></a>
<a name="line87"></a>function testLocalUrlWithContentDisposition() {
<a name="line88"></a>  downloader.download(&#39;/foo/bar&#39;).
<a name="line89"></a>      addCallback(function() { return downloader.getLocalUrl(&#39;/foo/bar&#39;); }).
<a name="line90"></a>      addCallback(function(url) { assertMatches(/\/`qux`22bap$/, url); }).
<a name="line91"></a>      addCallback(goog.bind(asyncTestCase.continueTesting, asyncTestCase)).
<a name="line92"></a>      addErrback(function(err) { throw err; });
<a name="line93"></a>
<a name="line94"></a>  xhr.simulateResponse(
<a name="line95"></a>      200, &#39;data&#39;, {&#39;Content-Disposition&#39;: &#39;attachment; filename=&quot;qux\\&quot;bap&quot;&#39;});
<a name="line96"></a>  asyncTestCase.waitForAsync(&#39;testGetLocalUrl&#39;);
<a name="line97"></a>}
<a name="line98"></a>
<a name="line99"></a>function testIsDownloaded() {
<a name="line100"></a>  downloader.download(&#39;/foo/bar&#39;).
<a name="line101"></a>      addCallback(function() { return downloader.isDownloaded(&#39;/foo/bar&#39;); }).
<a name="line102"></a>      addCallback(assertTrue).
<a name="line103"></a>      addCallback(function() { return downloader.isDownloaded(&#39;/foo/baz&#39;); }).
<a name="line104"></a>      addCallback(assertFalse).
<a name="line105"></a>      addCallback(goog.bind(asyncTestCase.continueTesting, asyncTestCase)).
<a name="line106"></a>      addErrback(function(err) { throw err; });
<a name="line107"></a>
<a name="line108"></a>  xhr.simulateResponse(200, &#39;data&#39;);
<a name="line109"></a>  asyncTestCase.waitForAsync(&#39;testIsDownloaded&#39;);
<a name="line110"></a>}
<a name="line111"></a>
<a name="line112"></a>function testRemove() {
<a name="line113"></a>  downloader.download(&#39;/foo/bar&#39;).
<a name="line114"></a>      addCallback(function() { return downloader.remove(&#39;/foo/bar&#39;); }).
<a name="line115"></a>      addCallback(function() { return downloader.isDownloaded(&#39;/foo/bar&#39;); }).
<a name="line116"></a>      addCallback(assertFalse).
<a name="line117"></a>      addCallback(function() {
<a name="line118"></a>        return downloader.getDownloadedBlob(&#39;/foo/bar&#39;);
<a name="line119"></a>      }).
<a name="line120"></a>      addErrback(function(err) {
<a name="line121"></a>        assertEquals(goog.fs.Error.ErrorCode.NOT_FOUND, err.code);
<a name="line122"></a>        var download = downloader.download(&#39;/foo/bar&#39;);
<a name="line123"></a>        xhr.simulateResponse(200, &#39;more data&#39;);
<a name="line124"></a>        return download;
<a name="line125"></a>      }).
<a name="line126"></a>      addCallback(function() { return downloader.isDownloaded(&#39;/foo/bar&#39;); }).
<a name="line127"></a>      addCallback(assertTrue).
<a name="line128"></a>      addCallback(function() {
<a name="line129"></a>        return downloader.getDownloadedBlob(&#39;/foo/bar&#39;);
<a name="line130"></a>      }).
<a name="line131"></a>      addCallback(function(blob) {
<a name="line132"></a>        assertEquals(&#39;more data&#39;, blob.toString());
<a name="line133"></a>      }).
<a name="line134"></a>      addCallback(goog.bind(asyncTestCase.continueTesting, asyncTestCase));
<a name="line135"></a>
<a name="line136"></a>  xhr.simulateResponse(200, &#39;data&#39;);
<a name="line137"></a>  asyncTestCase.waitForAsync(&#39;testRemove&#39;);
<a name="line138"></a>}
<a name="line139"></a>
<a name="line140"></a>function testSetBlob() {
<a name="line141"></a>  downloader.setBlob(&#39;/foo/bar&#39;, goog.testing.fs.getBlob(&#39;data&#39;)).
<a name="line142"></a>      addCallback(function() { return downloader.isDownloaded(&#39;/foo/bar&#39;); }).
<a name="line143"></a>      addCallback(assertTrue).
<a name="line144"></a>      addCallback(function() {
<a name="line145"></a>        return downloader.getDownloadedBlob(&#39;/foo/bar&#39;);
<a name="line146"></a>      }).
<a name="line147"></a>      addCallback(function(blob) {
<a name="line148"></a>        assertEquals(&#39;data&#39;, blob.toString());
<a name="line149"></a>      }).
<a name="line150"></a>      addCallback(goog.bind(asyncTestCase.continueTesting, asyncTestCase)).
<a name="line151"></a>      addErrback(function(err) { throw err; });
<a name="line152"></a>
<a name="line153"></a>  asyncTestCase.waitForAsync(&#39;testSetBlob&#39;);
<a name="line154"></a>}
<a name="line155"></a>
<a name="line156"></a>function testSetBlobWithName() {
<a name="line157"></a>  downloader.setBlob(&#39;/foo/bar&#39;, goog.testing.fs.getBlob(&#39;data&#39;), &#39;qux&#39;).
<a name="line158"></a>      addCallback(function() { return downloader.getLocalUrl(&#39;/foo/bar&#39;); }).
<a name="line159"></a>      addCallback(function(url) { assertMatches(/\/`qux$/, url); }).
<a name="line160"></a>      addCallback(goog.bind(asyncTestCase.continueTesting, asyncTestCase)).
<a name="line161"></a>      addErrback(function(err) { throw err; });
<a name="line162"></a>
<a name="line163"></a>  asyncTestCase.waitForAsync(&#39;testSetBlob&#39;);
<a name="line164"></a>}
<a name="line165"></a>
<a name="line166"></a>function testDownloadDuringDownload() {
<a name="line167"></a>  var download1 = downloader.download(&#39;/foo/bar&#39;);
<a name="line168"></a>  var download2 = downloader.download(&#39;/foo/bar&#39;);
<a name="line169"></a>
<a name="line170"></a>  download1.
<a name="line171"></a>      addCallback(function() { return download2; }).
<a name="line172"></a>      addCallback(function() {
<a name="line173"></a>        return downloader.getDownloadedBlob(&#39;/foo/bar&#39;);
<a name="line174"></a>      }).
<a name="line175"></a>      addCallback(function(blob) { assertEquals(&#39;data&#39;, blob.toString()); }).
<a name="line176"></a>      addCallback(goog.bind(asyncTestCase.continueTesting, asyncTestCase));
<a name="line177"></a>
<a name="line178"></a>  // There should only need to be one response for both downloads, since the
<a name="line179"></a>  // second should return the same deferred as the first.
<a name="line180"></a>  xhr.simulateResponse(200, &#39;data&#39;);
<a name="line181"></a>  asyncTestCase.waitForAsync(&#39;testDownloadeduringDownload&#39;);
<a name="line182"></a>}
<a name="line183"></a>
<a name="line184"></a>function testGetDownloadedBlobDuringDownload() {
<a name="line185"></a>  var download = downloader.download(&#39;/foo/bar&#39;);
<a name="line186"></a>  downloader.waitForDownload(&#39;/foo/bar&#39;).addCallback(function() {
<a name="line187"></a>    return downloader.getDownloadedBlob(&#39;/foo/bar&#39;);
<a name="line188"></a>  }).addCallback(function(blob) {
<a name="line189"></a>    assertTrue(download.hasFired());
<a name="line190"></a>    assertEquals(&#39;data&#39;, blob.toString());
<a name="line191"></a>    asyncTestCase.continueTesting();
<a name="line192"></a>  });
<a name="line193"></a>
<a name="line194"></a>  xhr.simulateResponse(200, &#39;data&#39;);
<a name="line195"></a>  asyncTestCase.waitForAsync(&#39;testGetDownloadedBlobDuringDownload&#39;);
<a name="line196"></a>}
<a name="line197"></a>
<a name="line198"></a>function testIsDownloadedDuringDownload() {
<a name="line199"></a>  var download = downloader.download(&#39;/foo/bar&#39;);
<a name="line200"></a>  downloader.waitForDownload(&#39;/foo/bar&#39;).addCallback(function() {
<a name="line201"></a>    return downloader.isDownloaded(&#39;/foo/bar&#39;);
<a name="line202"></a>  }).addCallback(function(isDownloaded) {
<a name="line203"></a>    assertTrue(download.hasFired());
<a name="line204"></a>    assertTrue(isDownloaded);
<a name="line205"></a>    asyncTestCase.continueTesting();
<a name="line206"></a>  });
<a name="line207"></a>
<a name="line208"></a>  xhr.simulateResponse(200, &#39;data&#39;);
<a name="line209"></a>  asyncTestCase.waitForAsync(&#39;testIsDownloadedDuringDownload&#39;);
<a name="line210"></a>}
<a name="line211"></a>
<a name="line212"></a>function testRemoveDuringDownload() {
<a name="line213"></a>  var download = downloader.download(&#39;/foo/bar&#39;);
<a name="line214"></a>  downloader.
<a name="line215"></a>      waitForDownload(&#39;/foo/bar&#39;).
<a name="line216"></a>      addCallback(function() { return downloader.remove(&#39;/foo/bar&#39;); }).
<a name="line217"></a>      addCallback(function() { assertTrue(download.hasFired()); }).
<a name="line218"></a>      addCallback(function() { return downloader.isDownloaded(&#39;/foo/bar&#39;); }).
<a name="line219"></a>      addCallback(assertFalse).
<a name="line220"></a>      addCallback(goog.bind(asyncTestCase.continueTesting, asyncTestCase));
<a name="line221"></a>
<a name="line222"></a>  xhr.simulateResponse(200, &#39;data&#39;);
<a name="line223"></a>  asyncTestCase.waitForAsync(&#39;testRemoveDuringDownload&#39;);
<a name="line224"></a>}
<a name="line225"></a>
<a name="line226"></a>function testSetBlobDuringDownload() {
<a name="line227"></a>  var download = downloader.download(&#39;/foo/bar&#39;);
<a name="line228"></a>  downloader.
<a name="line229"></a>      waitForDownload(&#39;/foo/bar&#39;).
<a name="line230"></a>      addCallback(function() {
<a name="line231"></a>        return downloader.setBlob(
<a name="line232"></a>            &#39;/foo/bar&#39;, goog.testing.fs.getBlob(&#39;blob data&#39;));
<a name="line233"></a>      }).
<a name="line234"></a>      addErrback(function(err) {
<a name="line235"></a>        assertEquals(
<a name="line236"></a>            goog.fs.Error.ErrorCode.INVALID_MODIFICATION, err.fileError.code);
<a name="line237"></a>        return download;
<a name="line238"></a>      }).
<a name="line239"></a>      addCallback(function() {
<a name="line240"></a>        return downloader.getDownloadedBlob(&#39;/foo/bar&#39;);
<a name="line241"></a>      }).
<a name="line242"></a>      addCallback(function(b) { assertEquals(&#39;xhr data&#39;, b.toString()); }).
<a name="line243"></a>      addCallback(goog.bind(asyncTestCase.continueTesting, asyncTestCase));
<a name="line244"></a>
<a name="line245"></a>  xhr.simulateResponse(200, &#39;xhr data&#39;);
<a name="line246"></a>  asyncTestCase.waitForAsync(&#39;testSetBlobDuringDownload&#39;);
<a name="line247"></a>}
<a name="line248"></a>
<a name="line249"></a>function testDownloadCancelledBeforeXhr() {
<a name="line250"></a>  var download = downloader.download(&#39;/foo/bar&#39;);
<a name="line251"></a>  download.cancel();
<a name="line252"></a>
<a name="line253"></a>  download.
<a name="line254"></a>      addErrback(function() {
<a name="line255"></a>    assertEquals(&#39;/foo/bar&#39;, xhr.getLastUri());
<a name="line256"></a>    assertEquals(goog.net.ErrorCode.ABORT, xhr.getLastErrorCode());
<a name="line257"></a>    assertFalse(xhr.isActive());
<a name="line258"></a>
<a name="line259"></a>    return downloader.isDownloaded(&#39;/foo/bar&#39;);
<a name="line260"></a>  }).
<a name="line261"></a>      addCallback(assertFalse).
<a name="line262"></a>      addCallback(goog.bind(asyncTestCase.continueTesting, asyncTestCase));
<a name="line263"></a>
<a name="line264"></a>  asyncTestCase.waitForAsync(&#39;testDownloadCancelledBeforeXhr&#39;);
<a name="line265"></a>}
<a name="line266"></a>
<a name="line267"></a>function testDownloadCancelledAfterXhr() {
<a name="line268"></a>  var download = downloader.download(&#39;/foo/bar&#39;);
<a name="line269"></a>  xhr.simulateResponse(200, &#39;data&#39;);
<a name="line270"></a>  download.cancel();
<a name="line271"></a>
<a name="line272"></a>  download.
<a name="line273"></a>      addErrback(function() {
<a name="line274"></a>    assertEquals(&#39;/foo/bar&#39;, xhr.getLastUri());
<a name="line275"></a>    assertEquals(goog.net.ErrorCode.NO_ERROR, xhr.getLastErrorCode());
<a name="line276"></a>    assertFalse(xhr.isActive());
<a name="line277"></a>
<a name="line278"></a>    return downloader.isDownloaded(&#39;/foo/bar&#39;);
<a name="line279"></a>  }).
<a name="line280"></a>      addCallback(assertFalse).
<a name="line281"></a>      addCallback(goog.bind(asyncTestCase.continueTesting, asyncTestCase));
<a name="line282"></a>
<a name="line283"></a>  asyncTestCase.waitForAsync(&#39;testDownloadCancelledAfterXhr&#39;);
<a name="line284"></a>}
<a name="line285"></a>
<a name="line286"></a>function testFailedXhr() {
<a name="line287"></a>  downloader.download(&#39;/foo/bar&#39;).
<a name="line288"></a>      addErrback(function(err) {
<a name="line289"></a>        assertEquals(&#39;/foo/bar&#39;, err.url);
<a name="line290"></a>        assertEquals(404, err.xhrStatus);
<a name="line291"></a>        assertEquals(goog.net.ErrorCode.HTTP_ERROR, err.xhrErrorCode);
<a name="line292"></a>        assertUndefined(err.fileError);
<a name="line293"></a>
<a name="line294"></a>        return downloader.isDownloaded(&#39;/foo/bar&#39;);
<a name="line295"></a>      }).
<a name="line296"></a>      addCallback(assertFalse).
<a name="line297"></a>      addCallback(goog.bind(asyncTestCase.continueTesting, asyncTestCase));
<a name="line298"></a>
<a name="line299"></a>  xhr.simulateResponse(404);
<a name="line300"></a>  asyncTestCase.waitForAsync(&#39;testFailedXhr&#39;);
<a name="line301"></a>}
<a name="line302"></a>
<a name="line303"></a>function testFailedDownloadSave() {
<a name="line304"></a>  downloader.download(&#39;/foo/bar&#39;).
<a name="line305"></a>      addCallback(function() {
<a name="line306"></a>        var download = downloader.download(&#39;/foo/bar&#39;);
<a name="line307"></a>        xhr.simulateResponse(200, &#39;data&#39;);
<a name="line308"></a>        return download;
<a name="line309"></a>      }).
<a name="line310"></a>      addErrback(function(err) {
<a name="line311"></a>        assertEquals(&#39;/foo/bar&#39;, err.url);
<a name="line312"></a>        assertUndefined(err.xhrStatus);
<a name="line313"></a>        assertUndefined(err.xhrErrorCode);
<a name="line314"></a>        assertEquals(
<a name="line315"></a>            goog.fs.Error.ErrorCode.INVALID_MODIFICATION, err.fileError.code);
<a name="line316"></a>
<a name="line317"></a>        asyncTestCase.continueTesting();
<a name="line318"></a>      });
<a name="line319"></a>
<a name="line320"></a>  xhr.simulateResponse(200, &#39;data&#39;);
<a name="line321"></a>  asyncTestCase.waitForAsync(&#39;testFailedDownloadSave&#39;);
<a name="line322"></a>}
<a name="line323"></a>
<a name="line324"></a>function testFailedGetDownloadedBlob() {
<a name="line325"></a>  downloader.getDownloadedBlob(&#39;/foo/bar&#39;).
<a name="line326"></a>      addErrback(function(err) {
<a name="line327"></a>        assertEquals(goog.fs.Error.ErrorCode.NOT_FOUND, err.code);
<a name="line328"></a>        asyncTestCase.continueTesting();
<a name="line329"></a>      });
<a name="line330"></a>
<a name="line331"></a>  asyncTestCase.waitForAsync(&#39;testFailedGetDownloadedBlob&#39;);
<a name="line332"></a>}
<a name="line333"></a>
<a name="line334"></a>function testFailedRemove() {
<a name="line335"></a>  downloader.remove(&#39;/foo/bar&#39;).
<a name="line336"></a>      addErrback(function(err) {
<a name="line337"></a>        assertEquals(goog.fs.Error.ErrorCode.NOT_FOUND, err.code);
<a name="line338"></a>        asyncTestCase.continueTesting();
<a name="line339"></a>      });
<a name="line340"></a>
<a name="line341"></a>  asyncTestCase.waitForAsync(&#39;testFailedRemove&#39;);
<a name="line342"></a>}
<a name="line343"></a>
<a name="line344"></a>function testIsDownloading() {
<a name="line345"></a>  assertFalse(downloader.isDownloading(&#39;/foo/bar&#39;));
<a name="line346"></a>  downloader.download(&#39;/foo/bar&#39;).addCallback(function() {
<a name="line347"></a>    assertFalse(downloader.isDownloading(&#39;/foo/bar&#39;));
<a name="line348"></a>    asyncTestCase.continueTesting();
<a name="line349"></a>  });
<a name="line350"></a>
<a name="line351"></a>  assertTrue(downloader.isDownloading(&#39;/foo/bar&#39;));
<a name="line352"></a>
<a name="line353"></a>  xhr.simulateResponse(200, &#39;data&#39;);
<a name="line354"></a>  asyncTestCase.waitForAsync(&#39;testIsDownloading&#39;);
<a name="line355"></a>}
<a name="line356"></a>
<a name="line357"></a>function testIsDownloadingWhenCancelled() {
<a name="line358"></a>  assertFalse(downloader.isDownloading(&#39;/foo/bar&#39;));
<a name="line359"></a>  var deferred = downloader.download(&#39;/foo/bar&#39;).addErrback(function() {
<a name="line360"></a>    assertFalse(downloader.isDownloading(&#39;/foo/bar&#39;));
<a name="line361"></a>  });
<a name="line362"></a>
<a name="line363"></a>  assertTrue(downloader.isDownloading(&#39;/foo/bar&#39;));
<a name="line364"></a>  deferred.cancel();
<a name="line365"></a>}
<a name="line366"></a>
<a name="line367"></a>function assertMatches(expected, actual) {
<a name="line368"></a>  assert(
<a name="line369"></a>      &#39;Expected &quot;&#39; + actual + &#39;&quot; to match &#39; + expected,
<a name="line370"></a>      expected.test(actual));
<a name="line371"></a>}
</pre>


</body>
</html>
